//
//  StoreCouponsCell.m
//  GoBigMarket
//
//  Created by 李真 on 2016/11/3.
//  Copyright © 2016年 legend. All rights reserved.
//

#import "StoreCouponsCell.h"

@implementation StoreCouponsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)setModel:(StoreCouponsModel *)model{
    if (_model != model) {
        _model = model;
    }
    DLog(@"ID_%@ EndTime_%@ Name_%@ Price_%@ OrderAmount_%@",model.Id,model.EndTime,model.CouponName,model.Price,model.OrderAmount);
    self.nameLabel.text = model.CouponName;
//    self.nameLabel.text = @"10元优惠券";
    self.CouponTextLabel.attributedText = [self textLabelWithOrderAmount:model.OrderAmount WithPrice:model.Price];
    self.endTimeLabel.text = [NSString stringWithFormat:@"有效期至:%@",model.EndTime];
    if (FourInch) {
        self.nameLabel.font = [UIFont systemFontOfSize:17.0f];
    }
//    self.QuanImageView.image = [self addText:[UIImage imageNamed:@"yoHuiQuan"] withId:model.Id withEndTime:model.EndTime withCouponName:model.CouponName WithPrice:model.Price withOrderAmount:model.OrderAmount];
}

#pragma mark - 富文本设置
- (NSAttributedString *)textLabelWithOrderAmount:(NSString *)OrderAmount WithPrice:(NSString *)price{
    //售价
    NSString *str = [NSString stringWithFormat:@"消费满%@立减%@元",OrderAmount,price];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:str];
    
    [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:35.0f] range:NSMakeRange(str.length - price.length - 1, price.length)];
    
    return attributedString;
}

#pragma mark - 绘制优惠券(未使用)
-(UIImage *)addText:(UIImage *)img withId:(NSString *)ID withEndTime:(NSString *)endtime withCouponName:(NSString *)couponName WithPrice:(NSString *)price withOrderAmount:(NSString *)OrderAmount
{
    UIImage *image = img;
    
    CGSize size=CGSizeMake(XNWindowWidth, XNWindowWidth / 4);//画布大小
    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    //获得一个位图图形上下文
    CGContextRef context=UIGraphicsGetCurrentContext();
    CGContextDrawPath(context, kCGPathStroke);
    UIFont *font1 = [UIFont systemFontOfSize:15];
    UIFont *font2 = [UIFont systemFontOfSize:20 weight:.5f];
    UIFont *font3 = [UIFont systemFontOfSize:15];
    UIFont *font4 = [UIFont systemFontOfSize:20 weight:1.0f];
    if (FourInch) {
        font1 = [UIFont systemFontOfSize:15];
        font2 = [UIFont systemFontOfSize:15];
        font3 = [UIFont systemFontOfSize:15];
        font4 = [UIFont systemFontOfSize:15];
    }
    //优惠券名称
    [couponName drawWithRect:CGRectMake(10, 5, 15, XNWindowWidth / 4 - 10) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font1,NSForegroundColorAttributeName:[UIColor whiteColor]} context:nil];
//    [couponName drawAtPoint:CGPointMake(0, 0) withAttributes:@{NSFontAttributeName:font1,NSForegroundColorAttributeName:[UIColor whiteColor]}];
    //内容名称
    [[NSString stringWithFormat:@"消费满%@元立减%@元",OrderAmount,price] drawWithRect:CGRectMake(100, 40,XNWindowWidth - 100, 40) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font2,NSForegroundColorAttributeName:GDJColor(255, 0, 114)} context:nil];
    //到期时间
    [[NSString stringWithFormat:@"有效期至:%@",endtime] drawWithRect:CGRectMake(80,XNWindowWidth / 16 * 3, XNWindowWidth - 80, XNWindowWidth / 16) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font3,NSForegroundColorAttributeName:[UIColor grayColor]} context:nil];
    //优惠券
    [@"优惠券" drawWithRect:CGRectMake(40, 15, 20, XNWindowWidth / 4 - 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font4,NSForegroundColorAttributeName:GDJColor(255, 0, 114)} context:nil];
    
    UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return newImage;
}
@end
